﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;

namespace Cosoware.Web.Documents.SqlClient
{
    class SqlDataContext : DataContext
    {
        /// <summary>
        /// Representation of a table of documents.
        /// </summary>
        public Table<Document> Documents { get; internal set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="SqlDataContext"/> class.
        /// </summary>
        /// <param name="fileOrServerOrConnection">The file or server or connection.</param>
        public SqlDataContext(string fileOrServerOrConnection) : base(fileOrServerOrConnection)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SqlDataContext"/> class.
        /// </summary>
        /// <param name="fileOrServerOrConnection">The file or server or connection.</param>
        /// <param name="mapping">The mapping.</param>
        public SqlDataContext(string fileOrServerOrConnection, MappingSource mapping) : base(fileOrServerOrConnection, mapping)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SqlDataContext"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        public SqlDataContext(IDbConnection connection) : base(connection)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SqlDataContext"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="mapping">The mapping.</param>
        public SqlDataContext(IDbConnection connection, MappingSource mapping) : base(connection, mapping)
        {
            Initialize();
        }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private void Initialize()
        {
            Documents = GetTable<Document>();
        }
    }
}
